package com.vf.admin.client.controller;

import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.common.ClientConstants;
import com.vf.admin.client.common.RedisKeys;
import com.vf.admin.client.service.AppGiftNumService;
import com.vf.admin.client.service.AppGiftService;
import com.vf.admin.client.service.AppKnapsackService;
import com.vf.admin.client.service.AppUserService;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.redis.RedisUtil;
import com.vf.admin.miaodong.entity.AppGift;
import com.vf.admin.miaodong.entity.AppGiftNum;
import com.vf.admin.miaodong.entity.AppKnapsack;
import com.vf.admin.miaodong.entity.AppUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 礼物，粉丝团礼物，礼物数量，列表信息
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppGiftNumController.java
 * @Description TODO
 * @createTime 2021年07月23日 16:17:00
 */
@CrossOrigin
@Controller
@RequestMapping("/app/giftnum")
public class AppGiftNumController extends ClientBaseController{
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    AppGiftNumService appGiftNumService;
    @Autowired
    AppGiftService appGiftService;
    @Autowired
    AppUserService appUserService;
    @Autowired
    AppKnapsackService appKnapsackService;
    @Autowired
    RedisUtil redisUtil;

    /**
    * 礼物数量列表
    * @Param: []
    * @return: com.vf.admin.common.entity.Result
    * @Author: zhouyunyi
    * @Date: 2021/07/23
    * @Time: 17:04
    */
    @RequestMapping("/giftnum")
    @ResponseBody
    public Result giftnum(){
        try{
            Map<String,Object> map = new HashMap<>(16);
            List<AppGiftNum> list = appGiftNumService.list(map,null);

            map.clear();
            map.put("list",list);
            return this.sucessJSON(map);
        }catch (Exception e){
            logger.error("查询礼物数量列表异常",e);
            return this.errorJSON("系统繁忙");
        }
    }


    /**
    * 礼物，贵族礼物列表
    * @Param: [liwuguishu 礼物归属 1、普通礼物  2、贵族礼物
    * @return: com.vf.admin.common.entity.Result
    * @Author: zhouyunyi
    * @Date: 2021/07/23
    * @Time: 17:14
    */
    @RequestMapping("/gift")
    @ResponseBody
    public Result gift(){
        try{
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);
            Map<String,Object> toMap=new HashMap<>(16);
            //普通礼物
            Map<String, Object> params = new HashMap<>();
            params.put("liwuguishu", 1);
            params.put("isBeckoning", 2);
            params.put("status", 1);
            List<AppGift> giftList = appGiftService.findByList(params,null);
            //贵族礼物
            params = new HashMap<>();
            params.put("liwuguishu", 2);
            params.put("isBeckoning", 2);
            params.put("status", 1);
            List<AppGift> guizuList = appGiftService.findByList(params,null);
            toMap.put("giftList",giftList);
            toMap.put("guizuList",guizuList);
            toMap.put("diamonds",user.getDiamonds());
            toMap.put("jinbi",user.getJinbi());
            toMap.put("meili",user.getCharmvalue());
            return sucessJSON(toMap);
        }catch (Exception e){
            logger.error("查询礼物列表异常",e);
            return this.errorJSON("系统繁忙");
        }
    }

    /**
     * 获取我的背包
     * @Param: [pageNo 页码]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/23
     * @Time: 17:14
     */
    @RequestMapping("/getMeKnapsack")
    @ResponseBody
    public Result getMeKnapsack(HttpServletRequest request){
        try{
            //获取最新数据
            Integer userId = (Integer)redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user =appUserService.get(userId);
            //查询背包
            List<AppKnapsack> list = appKnapsackService.getBeibao(user.getId());

            return this.sucessJSON(list);
        }catch (Exception e){
            logger.error("获取我的背包异常",e);
            return this.errorJSON("系统繁忙");
        }
    }

}
